const app = getApp();
const util = require("../../../../utils/util");
var allServer = [];
Page({

  data: {
    allServer: [], // 一级二级目录
  },
  onLoad: function () {
    this.init();
  },
  init() {
    let $feedBackAllServer = {
      ac: "allServer",
      city: "sz",
      type: app.globalData.platform,
    };
    util.getUrl(app.globalData.url).then(res => {
      util.bstrequest('index.php', $feedBackAllServer, "POST").then(res => {
        allServer = JSON.parse(JSON.stringify(res.data));
        if (allServer.allServer1) {
          allServer.allServer1.forEach(v => {
            if (this.getNextServer(v.id))
              v.nextServer = this.getNextServer(v.id);
          });
          this.setData({
            allServer,
          });
        }
      });
    });
  },
  getNextServer(pid) {
    let nextServer = [];
    nextServer = allServer.allServer2.filter(v => v.pid == pid);
    return nextServer;
  },
  feedBack2Next(e) {
    let index1 = e.currentTarget.dataset.index1;
    let index2 = e.currentTarget.dataset.index2;
    let data = this.data.allServer.allServer1[index1].nextServer[index2];
    if (data.id === '2885') {
      ks.navigateTo({
        url: `index/index`,
      });
      util.clickNumber(data.id);
    }
    if (data.id === '2973') {
      ks.navigateTo({
        url: `shebao/shebao`,
      });
      util.clickNumber(data.id);
    }
    if (data.id === '2987') {
      ks.navigateTo({
        url: 'listQuery/listQuery',
      });
    }
    if (data.ser_name == '天气预报') {
      ks.navigateTo({
        url: 'weather/weather',
      });
      util.clickNumber(data.id, 1);
    }
    if (data.ser_link_method != "0") {
      util.click2NextProgram(data);
      util.clickNumber(data.id);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      imageUrl: "http://imgbdb3.bendibao.com/xcxbdb/file/20212/9/20210209161843_68677.jpg"
    }
  }

});